Skip to content

fix: replace abort() with cooperative wait in wait_for_run_task#576

Draft
xdustinface wants to merge 2 commits intorefactor/move-callbacks-to-cratesfrom
fix/replace-abort
Draft

fix: replace abort() with cooperative wait in wait_for_run_task#576
xdustinface wants to merge 2 commits intorefactor/move-callbacks-to-cratesfrom
fix/replace-abort

Conversation

@xdustinface
Copy link
Collaborator

abort() can interrupt the cleanup sequence in DashSpvClient::run() (the monitor_shutdown.cancel() + tokio::join!), leaving monitor tasks running after FFI callback pointers are freed. Use cooperative wait with a timeout fallback instead.

Based on:

Introduce `EventHandler` trait in `dash-spv` with default no-op methods
and make `DashSpvClient` generic over it (`H: EventHandler`, default `()`).
The handler is passed at construction time and stored as `Arc<H>`:

- `DashSpvClient::new()` takes `Arc<H>` and emits initial progress
  via `on_progress()` immediately after construction
- `run()` subscribes to internal channels and dispatches events to the
  stored handler via monitoring tasks — no handler parameter needed
- `impl EventHandler for ()` provides a zero-cost no-op default
- `FFIEventCallbacks` implements `EventHandler` directly, eliminating
  the `FFIEventHandler` wrapper
- FFI: callbacks pass to `dash_spv_ffi_client_new()`, `run()` is
  parameter-less
- Add `TestEventHandler` that bridges events back to tokio channels
  for ergonomic `select!`-based integration tests
- Add `LoggingEventHandler` to CLI binary
`abort()` can interrupt the cleanup sequence in `DashSpvClient::run()`
(the `monitor_shutdown.cancel()` + `tokio::join!`), leaving monitor
tasks running after FFI callback pointers are freed. Use cooperative
wait with a timeout fallback instead.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6acab986-e31c-4abd-8456-6633e55a3ffb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/replace-abort

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 78.63248% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.51%. Comparing base (19fb152) to head (fabbdad).
⚠️ Report is 1 commits behind head on refactor/move-callbacks-to-crates.

Files with missing lines Patch % Lines
dash-spv-ffi/src/bin/ffi_cli.rs 0.00% 39 Missing ⚠️
dash-spv/src/main.rs 0.00% 22 Missing ⚠️
dash-spv/src/client/event_handler.rs 95.71% 9 Missing ⚠️
dash-spv/src/client/sync_coordinator.rs 90.90% 3 Missing ⚠️
dash-spv-ffi/src/client.rs 90.90% 2 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##           refactor/move-callbacks-to-crates     #576      +/-   ##
=====================================================================
+ Coverage                              66.32%   66.51%   +0.18%     
=====================================================================
  Files                                    311      312       +1     
  Lines                                  64976    65018      +42     
=====================================================================
+ Hits                                   43097    43247     +150     
+ Misses                                 21879    21771     -108     
Flag Coverage Δ
core 75.13% <ø> (ø)
ffi 36.85% <46.05%> (+0.05%) ⬆️
rpc 28.28% <ø> (ø)
spv 81.22% <87.63%> (+0.15%) ⬆️
wallet 66.27% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv-ffi/src/callbacks.rs 79.59% <100.00%> (+16.11%) ⬆️
dash-spv/src/client/core.rs 46.00% <100.00%> (+1.10%) ⬆️
dash-spv/src/client/events.rs 100.00% <100.00%> (ø)
dash-spv/src/client/lifecycle.rs 64.15% <100.00%> (+0.68%) ⬆️
dash-spv/src/client/mempool.rs 57.57% <ø> (ø)
dash-spv/src/client/mod.rs 98.64% <100.00%> (ø)
dash-spv/src/client/queries.rs 14.28% <ø> (ø)
dash-spv/src/client/transactions.rs 0.00% <ø> (ø)
dash-spv-ffi/src/client.rs 58.73% <90.90%> (-0.66%) ⬇️
dash-spv/src/client/sync_coordinator.rs 82.45% <90.90%> (+9.72%) ⬆️
... and 3 more

... and 4 files with indirect coverage changes

@xdustinface xdustinface force-pushed the refactor/move-callbacks-to-crates branch from aaddece to 23accc0 Compare March 23, 2026 06:04
@github-actions
Copy link

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@github-actions github-actions bot added the merge-conflict The PR conflicts with the target branch. label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR conflicts with the target branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant